﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

using zijian666.Converts;
using zijian666.Converts.Core;
using zijian666.Converts.Extensions;

namespace UnitTest
{
    class DiagnosticObserver : IObserver<DiagnosticListener>, IObserver<KeyValuePair<string, object>>
    {
        void IObserver<DiagnosticListener>.OnCompleted()
        {

        }

        void IObserver<DiagnosticListener>.OnError(Exception error)
        {

        }

        void IObserver<DiagnosticListener>.OnNext(DiagnosticListener value)
        {
            if (value.Name == "zijian666.Converts")
            {
                value.Subscribe(this);
            }
        }

        void IObserver<KeyValuePair<string, object>>.OnCompleted()
        {
        }

        void IObserver<KeyValuePair<string, object>>.OnError(Exception error)
        {
            Console.WriteLine($"error: {error}");
        }

        void IObserver<KeyValuePair<string, object>>.OnNext(KeyValuePair<string, dynamic> value)
        {
            if (value.Key == "Exception")
            {
                Console.WriteLine(  );
            }
            Console.WriteLine($"DiagnosticListener: [{value.Key}] {value.Value}");
            //switch (value.Key)
            //{
            //    case "Converting":
            //        Console.WriteLine($"DiagnosticListener: [Converting] {value.Value.convertor}");
            //        Console.WriteLine($"DiagnosticListener: [Value] `{value.Value.value}`");
            //        break;
            //    case "Converted":
            //        Console.WriteLine($"DiagnosticListener: [Result] `{value.Value.result}`");
            //        break;
            //    case "Exception":
            //        Console.WriteLine($"DiagnosticListener: [Error] `{value.Value.exception.Message}`");
            //        break;
            //    default:
            //        break;
            //}
        }
    }
}
